<?php

/**
 * User Resources Model
 *
 */
class Application_Model_UserResources implements Zend_Acl_Resource_Interface 
{
    protected $_resource;

    public function __construct($resource=null)
    {
        $this->_resource=$resource;
    }
    
    /**
     * Returns valid user resources
     *
     * @return array
     */
    static function getValidResources()
    {
        return Zend_Registry::get('resources');
    }
    
    /**
     * Returns not valid resource !!!
     *
     * @return string
     */
    static function getDefaultResource()
    {
        return 'void';
    }
    
    /**
     * Returns front page resource name
     *
     * @return string
     */
    static function getFrontResource()
    {
        return 'index';
    }
    
    /**
     * Returns user resource name
     *
     * @return string
     */
    static function getUserResource()
    {
        return Application_Model_User::RESOURCE_NAME;
    }
    
    /**
     * Returns node resource name
     *
     * @return string
     */
    static function getNodeResource()
    {
        return Application_Model_Node::RESOURCE_NAME;
    }
    
    /**
     * Returns file resource name
     *
     * @return string
     */
    static function getFileResource()
    {
        return Application_Model_File::RESOURCE_NAME;
    }
    
    /**
     * Returns log resource name
     *
     * @return string
     */
    static function getLogResource()
    {
        return Application_Model_Log::RESOURCE_NAME;
    }
    
    /**
     * Returns cache resource name
     *
     * @return string
     */
    static function getCacheResource()
    {
        return Application_Model_Cache::RESOURCE_NAME;
    }
    
    /**
     * Checks if given resource is valid
     *
     * @param string $resource
     * @return bool
     */
    static function isValidResource($resource)
    {
        if (empty($resource)) return false;
        
        $resources=self::getValidResources();
        
        return in_array($resource,$resources) ? true : false;
    }
    
    /**
     * Returns active user resource
     *
     * @return string
     */
    protected function _getActiveResource()
    {
        return Zend_Registry::get('resource');
    }
    
    /**
     * ACL getResourceId interface function
     *
     * @return string
     */
    public function getResourceId()
    {
        if (!empty($this->_resource)) return $this->_resource;
        
        return $this->_getActiveResource();
    }
}

